package com.qf.dao;

import com.qf.common.dto.NewsDto;
import com.qf.entity.News;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @description: cool新闻
 * @author: No1
 * @create: 2020-11-30 11:33:07
 */
@Repository
public interface NewsDao {
//    /*新增*/
//    @Insert("insert into t_news (id,uid,tid,title,image_url,video_url,time,content,ctime,flag) values(#{id},#{uid},#{tid},#{title},#{image_url},#{video_url},#{time},#{content},#{ctime},#{flag})")
//    int insert(News news);
//
    /*删除视频*/
    @Delete("delete from t_news where id=#{id}")
    int deleteById(int id);

    /*查询全部视频*/
    @Select("select t_news.title title, t_news.time time, t_news.video_url video, t_userdetail.image_url userImage,\n" +
            "t_userdetail.nickname authName, COUNT(t_npraise.uid)  likeNum, t_comment.`comment` comment,\n" +
            "COUNT(t_comment.uid1) commentNum\n" +
            "from t_news  LEFT JOIN  t_userdetail on t_news.aid = t_userdetail.id\n" +
            "RIGHT  JOIN \n" +
            "t_comment on t_news.id = t_comment.nid INNER JOIN t_npraise on t_news.id = t_npraise.nid \n" +
            "where t_news.flag = 2 and t_news.tid = #{tid}")
    @ResultType(NewsDto.class)

    List<NewsDto> all(String tid);
//    添加点赞信息
    @Insert("insert into t_npraise (uid, nid) values(#{aid}, #{id})")
    int insertNpraise(String id, String aid);

//    添加评论信息
    @Insert("insert into t_comment (uid1, nid, comment, ctime) values(#{aid}, #{id}, #{comment}, now())")
    int insertComment(String id, String aid, String comment);

    // 上传视频
    @Insert("insert into t_news (aid, tid, title, video_url, time, flag, ctime) values(#{news.uid}, #{news.tid}, #{news.title}, #{news.video_url}, #{news.time}, #{flag}, now()")
    int insert(News news, String flag);



}